import redis
from base import logger
from base.server_conf import Redis as redis_conf

redis_host = redis_conf["host"]
redis_port = redis_conf["port"]

g_redis_pool = None

def getRedis() -> redis.Redis: 
    global g_redis_pool
    if not g_redis_pool:
        g_redis_pool = redis.ConnectionPool(
            host=redis_host,
            port=redis_port,
            decode_responses=True,
        )
    if not g_redis_pool:
        logger.error(f"redis pool create error redis_host={redis_host}, redis_port={redis_port}")
        return None
    return redis.Redis(connection_pool=g_redis_pool)
